<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                                  |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: liguohua@clcw.com.cn Blog:http://blog.sina.com.cn/saverneo     |
// +------------------------------------------------------------------------+
//
/**
 * 拍单管理
 */
namespace AuctionBack\Controller;

use AuctionCore\CarResource\CarReport;
use AuctionCore\CarResource\Car;
use AuctionBack\Service\CarService;

class CarReportController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 报告输出
     */
    public function output_report($car_id)
    {
        $car = new CarService($car_id);
        $rep = new CarReport($car_id);
        $report = $rep->report();
        $report['damage_pics'] = $car->damage_pics();
        $report['base_pics_count'] = count($report['base_pics']);
        //--------------------骨架可见损伤图片
        //轻微损伤图片(大图，轮播)
        $pics = $car->get_all_pics(true, 'frame');


        $report['frame_pics_big'] = json_decode($pics, true);
        //轻微损伤图片(小图,轮播)
        $report['frame_pics_sma'] = array();
        foreach ($report['frame_pics_big'] as $k => $v) {
            $report['frame_pics_sma'][$k]['url'] = $v['url'] . '@124w_74h_4e';
        }
        //张数
        $report['frame_pics_count'] = count($report['frame_pics_big']);

        //--------------------外观可见损伤图片
        //轻微损伤图片(大图，轮播)
        $pics = $car->get_all_pics(true, 'outside');
        $report['outside_pics_big'] = json_decode($pics, true);
        //轻微损伤图片(小图,轮播)
        $report['outside_pics_sma'] = array();
        foreach ($report['outside_pics_big'] as $k => $v) {
            $report['outside_pics_sma'][$k]['url'] = $v['url'] . '@124w_74h_4e';
        }
        //张数
        $report['outside_pics_count'] = count($report['outside_pics_big']);

        //--------------------内饰可见损伤图片
        //轻微损伤图片(大图，轮播)
        $pics = $car->get_all_pics(true, 'inside');
        $report['inside_pics_big'] = json_decode($pics, true);
        //轻微损伤图片(小图,轮播)
        $report['inside_pics_sma'] = array();
        foreach ($report['inside_pics_big'] as $k => $v) {
            $report['inside_pics_sma'][$k]['url'] = $v['url'] . '@124w_74h_4e';
        }
        //张数
        $report['inside_pics_count'] = count($report['inside_pics_big']);

        //--------------------轻微损伤图片
        //报告页4张展示小图
        $a = $car->get_dm_pic('2');
        foreach ($a as $k => $v) {
            $v['url'] = $v['url'] . '@180w_120h_4e';
            $a[$k] = $v;
        }
        $report['light_pics'] = $a;
        unset($k);
        unset($v);

        //轻微损伤图片(大图，轮播)
        $pics = $car->get_all_pics(true, 'light');
        $report['light_pics_big'] = json_decode($pics, true);
        //轻微损伤图片(小图,轮播)
        $report['light_pics_sma'] = array();
        foreach ($report['light_pics_big'] as $k => $v) {
            $report['light_pics_sma'][$k]['url'] = $v['url'] . '@124w_74h_4e';
        }
        //张数
        $report['light_pics_count'] = count($report['light_pics_big']);
        $report['light_pics_count_4'] = 4 - $report['light_pics_count'];

        //---------------------一般损伤图片
        //报告页4张展示小图
        $b = $car->get_dm_pic('3');

        foreach ($b as $k => $v) {
            $v['url'] = $v['url'] . '@180w_120h_4e';
            $b[$k] = $v;
        }
        $report['normal_pics'] = $b;
        unset($k);
        unset($v);

        //一般损伤图片(大图，轮播)
        $pics = $car->get_all_pics(true, 'normal');

        $report['normal_pics_big'] = json_decode($pics, true);
        //一般损伤图片(小图,轮播)
        $report['normal_pics_sma'] = array();
        foreach ($report['normal_pics_big'] as $k => $v) {
            $report['normal_pics_sma'][$k]['url'] = $v['url'] . '@124w_74h_4e';
        }
        //张数
        $report['normal_pics_count'] = count($report['normal_pics_big']);
        $report['normal_pics_count_4'] = 4 - $report['normal_pics_count'];

        //----------------------重要损伤图片
        //报告页4张展示小图
        $c = $car->get_dm_pic('4');
        foreach ($c as $k => $v) {
            $v['url'] = $v['url'] . '@180w_120h_4e';
            $c[$k] = $v;
        }
        $report['important_pics'] = $c;
        unset($k);
        unset($v);

        //重要损伤图片(大图，轮播)
        $pics = $car->get_all_pics(true, 'important');
        $report['important_pics_big'] = json_decode($pics, true);
        //重要损伤图片(小图,轮播)
        $report['important_pics_sma'] = array();
        foreach ($report['important_pics_big'] as $k => $v) {
            $report['important_pics_sma'][$k]['url'] = $v['url'] . '@124w_74h_4e';
        }
        //张数
        $report['important_pics_count'] = count($report['important_pics_big']);
        $report['important_pics_count_4'] = 4 - $report['important_pics_count'];

        $this->assign('report', $report);
        $html = $this->view->fetch("CarReport/output_report");
        return $html;
    }

    /**
     * 获取损伤图片
     */
    public function dm_pic_to_json()
    {

        //获取车辆编号
        $car_no = I('get.car_no', '');
        if (empty($car_no)) {
            exit;
        }
        $carInfo = Car::get_car_by_car_no($car_no);
        if (empty($carInfo)) {
            exit;
        }
        $car = new CarReport($carInfo['car_id']);
        $car->dm_pic_to_json();
    }

}